 package server.console.groups.datamanage;




import com.alee.extended.button.WebSwitch;
import com.alee.extended.layout.TableLayout;
import com.alee.extended.painter.TitledBorderPainter;
import com.alee.extended.panel.CenterPanel;
import com.alee.extended.panel.GroupPanel;
import com.alee.extended.panel.GroupingType;
import com.alee.extended.panel.WebButtonGroup;
import com.alee.laf.button.WebButton;
import com.alee.laf.checkbox.WebCheckBox;
import com.alee.laf.label.WebLabel;
import com.alee.laf.menu.WebMenuItem;
import com.alee.laf.menu.WebPopupMenu;
import com.alee.laf.optionpane.WebOptionPane;
import com.alee.laf.panel.WebPanel;
import com.alee.laf.radiobutton.WebRadioButton;
import com.alee.laf.rootpane.WebDialog;
import com.alee.laf.rootpane.WebFrame;
import com.alee.laf.scroll.WebScrollPane;
import com.alee.laf.separator.WebSeparator;
import com.alee.laf.table.WebTable;
import com.alee.laf.text.WebTextField;
import com.alee.managers.hotkey.Hotkey;
import com.alee.managers.hotkey.HotkeyManager;
import com.alee.utils.SwingUtils;
import com.alee.utils.swing.UnselectableButtonGroup;
import server.console.Start;
import tools.Pair;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.*;
import java.util.List;





































 public abstract class TabbedPane extends WebPanel {
/*  41 */   protected final WebTable idTable = new WebTable(); protected final WebFrame owner;
/*  42 */   protected final WebTable dataTable = new WebTable();
/*  43 */   final Vector<String> idTableName = new Vector<>();
/*  44 */   final Vector<String> dataTableName = new Vector<>();
/*  45 */   final List<Pair<Boolean, String>> allDataTableName = new ArrayList<>(); protected WebButton button_ok;
   protected WebButton button_cancel;
   protected WebButton button_apply;

   TabbedPane(WebFrame owner) {
/*  50 */     this.owner = owner;
   }





   protected DefaultTableModel getIDTableModel() {
/*  58 */     return new DefaultTableModel(null, this.idTableName);
   }

   protected Map<String, Pair<Boolean, DefaultTableModel>> getMultiIDTableModel() {
/*  62 */     return null;
   }

   protected DefaultTableModel getDataTableModel() {
/*  66 */     return new DefaultTableModel(null, this.dataTableName);
   }

   public List<Pair<Boolean, String>> getAllDataTableName() {
/*  70 */     return this.allDataTableName;
   }

   public Component getPreview() {
/*  74 */     init();
/*  75 */     ((BorderLayout)getLayout()).setHgap(0);
/*  76 */     ((BorderLayout)getLayout()).setVgap(0);
/*  77 */     add(getLeftComponent(), "West");
/*  78 */     add(getCenterComponent());
/*  79 */     add(getSouthComponent(), "South");
/*  80 */     return (Component)this;
   }

 protected Component getSouthComponent() {
    button_ok = new WebButton("确定") {
        {
            addActionListener(new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    applyChange(true);
                    button_apply.setEnabled(false);
                    DataManagePanel.getInstance().dispose();
                }
            });
        }
    };
    button_cancel = new WebButton("取消") {
        {
            addActionListener(new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    applyChange(false);
                    button_apply.setEnabled(false);
                    DataManagePanel.getInstance().dispose();
                }
            });
        }
    };
    button_apply = new WebButton("应用") {
        {
            addActionListener(new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    applyChange(true);
                    button_apply.setEnabled(false);
                }
            });
        }
    };

    button_apply.setEnabled(false);
    button_ok.setPreferredWidth(100);
    SwingUtils.equalizeComponentsSize(button_ok, button_cancel, button_apply);
    return new WebPanel(new BorderLayout(5, 5)) {
        {
            add(new WebSeparator(true), BorderLayout.NORTH);
            add(new WebButtonGroup(true, button_ok, button_cancel, button_apply).setMargin(0, 0, 5, 5), BorderLayout.EAST);
        }
    };
}




   protected Component getLeftComponent() {
/*  89 */     WebPanel webPanel = new WebPanel(new BorderLayout(5, 5));
/*  90 */     WebScrollPane scrollPane = new WebScrollPane((Component)this.idTable);
/*  91 */     this.idTable.setEditable(false);
/*  92 */     this.idTable.setAutoResizeMode(4);
/*  93 */     this.idTable.setGridColor(Color.LIGHT_GRAY);
/*  94 */     if (showPopmenu()) {
/*  95 */       WebPopupMenu popupMenu = getTablePopupMenu(true);
/*  96 */       this.idTable.setComponentPopupMenu((JPopupMenu)popupMenu);
/*  97 */       scrollPane.setComponentPopupMenu((JPopupMenu)popupMenu);
     }
/*  99 */     this.idTable.addMouseListener(new TableMouseAdapter(true));
/* 100 */     if (!(this instanceof PlayerPane)) {
/* 101 */       this.idTable.getSelectionModel().addListSelectionListener(e -> {
             if (e.getValueIsAdjusting() || this.idTable.getRowCount() == 0 || this.idTable.getSelectedRow() == -1) {
               return;
             }

             this.dataTable.clearSelection();
             this.dataTable.setModel(getDataTableModel());
           });
     }
/* 110 */     GroupPanel typeGroup = null;
/* 111 */     if (getMultiIDTableModel() != null) {
/* 112 */       Map<String, Pair<Boolean, DefaultTableModel>> modelMap = getMultiIDTableModel();
/* 113 */       for (Pair<Boolean, DefaultTableModel> model : modelMap.values()) {
/* 114 */         if (((Boolean)model.getLeft()).booleanValue()) {
/* 115 */           this.idTable.setModel((TableModel)model.getRight());
           break;
         }
       }
/* 119 */       if (modelMap.size() > 1) {
/* 120 */         typeGroup = new GroupPanel(5, false, new Component[0]);
/* 121 */         typeGroup.setMargin(0, 5, 5, 5);
/* 122 */         List<AbstractButton> radioButtons = new ArrayList<>();
/* 123 */         for (Map.Entry<String, Pair<Boolean, DefaultTableModel>> entry : modelMap.entrySet()) {
/* 124 */           WebRadioButton radioButton = new WebRadioButton(entry.getKey());
/* 125 */           radioButton.addActionListener(e -> {
                 if (((Boolean)((Pair)entry.getValue()).getLeft()).booleanValue()) {
                   this.idTable.setModel((TableModel)((Pair)entry.getValue()).getRight());
                   this.dataTable.setModel(new DefaultTableModel(null, this.dataTableName));
                 } else {
                   this.idTable.setModel(new DefaultTableModel(null, this.idTableName));
                   this.dataTable.setModel((TableModel)((Pair)entry.getValue()).getRight());
                 }
               });
/* 134 */           radioButtons.add(radioButton);
         }
/* 136 */         UnselectableButtonGroup unselectableButtonGroup = new UnselectableButtonGroup(radioButtons);
/* 137 */         unselectableButtonGroup.setUnselectable(false);
/* 138 */         ((AbstractButton)radioButtons.get(0)).setSelected(true);
/* 139 */         typeGroup.add(radioButtons);
/* 140 */         typeGroup.setPainter(new TitledBorderPainter("类型"));
       }
     } else {
/* 143 */       this.idTable.setModel(getIDTableModel());
     }
/* 145 */     webPanel.setPreferredWidth(200);
/* 146 */     webPanel.add((typeGroup == null) ? getSearchGroup() : (Component)new GroupPanel(false, new Component[] { getSearchGroup(), (Component)typeGroup }), "North");
/* 147 */     webPanel.add((Component)scrollPane);
/* 148 */     webPanel.setMargin(5, 5, 5, 0);
/* 149 */     return (Component)webPanel;
   }

   protected Component getSearchGroup() {
/* 153 */     final WebTextField searchTextField = new WebTextField()
       {

       };





/* 162 */     WebCheckBox checkBoxShow = new WebCheckBox("显示搜索结果", isSelectedSearchResult())
       {

       };


/* 168 */     WebCheckBox checkBoxLike = new WebCheckBox("模糊搜索", isSelectedSearchFuzzy())
       {

       };


/* 174 */     WebButton searchButton = new WebButton(Start.loadIcon("search.png"))
       {

       };




/* 182 */     searchTextField.addActionListener(e -> searchButton.doClick());

/* 184 */     GroupPanel groupPanel1 = new GroupPanel(GroupingType.fillFirst, new Component[] { (Component)searchTextField, (Component)searchButton });
/* 185 */     GroupPanel groupPanel2 = new GroupPanel(10, new Component[] { (Component)checkBoxShow, (Component)checkBoxLike });
/* 186 */     GroupPanel mainGroupPanel = new GroupPanel(false, new Component[] { (Component)groupPanel1, (Component)groupPanel2 });

/* 188 */     mainGroupPanel.setPainter(new TitledBorderPainter("搜索"));
/* 189 */     mainGroupPanel.setMargin(0, 5, 5, 5);
/* 190 */     groupPanel2.setMargin(5, 2, 0, 0);
/* 191 */     return (Component)mainGroupPanel;
   }


   protected void doSearchAction(String result) {}


   protected Component getCenterComponent() {
    WebPanel webPanel = new WebPanel();

    GroupPanel operations = new GroupPanel();

    if (showOperation()) {
        for (Action action : getActions(false)) {
            operations.add(new WebButton(action) {
                {
                    setRolloverDecoratedOnly(true);
                    setDrawFocus(false);
                }
            });
        }
    }

    final WebPanel operationPane = new WebPanel();
    operationPane.add(operations, BorderLayout.WEST);
    if (showEditColumn()) {
        operationPane.add(new WebButton("设置列", Start.loadIcon("table.png")) {
            {
                setRolloverDecoratedOnly(true);
                setDrawFocus(false);
                addActionListener(new AbstractAction() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        WebDialog dialog = new WebDialog(owner, "设置显示列名", true);
                        dialog.setResizable(false);
                        GroupPanel groupPanel = new GroupPanel(5, false);
                        double[] doubles = new double[getAllDataTableName().size() + 1];
                        Arrays.fill(doubles, 0, doubles.length, TableLayout.PREFERRED);
                        groupPanel.setLayout(new TableLayout(new double[]{TableLayout.PREFERRED, TableLayout.FILL}, doubles, 5, 5));
                        for (int i = 0; i < getAllDataTableName().size(); i++) {
                            final Pair<Boolean, String> pair = getAllDataTableName().get(i);
                            final WebSwitch ws2 = new WebSwitch(pair.getLeft());
                            ws2.setRound(11);
                            ws2.setLeftComponent(createSwitchIcon(Start.loadIcon("ok.png"), 4, 0));
                            ws2.setRightComponent(createSwitchIcon(Start.loadIcon("off.png"), 0, 4));
                            ws2.addActionListener(new AbstractAction() {
                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    pair.left = ws2.isSelected();
                                    dataTable.setModel(getDataTableModel());
                                }
                            });
                            groupPanel.add(new WebLabel(pair.getRight(), WebLabel.TRAILING), "0," + i);
                            groupPanel.add(ws2, "1," + i);
                        }
                        groupPanel.setMargin(10, 20, 10, 20);
                        dialog.add(new CenterPanel(groupPanel));
                        dialog.pack();
                        dialog.setLocationRelativeTo(TabbedPane.this);
                        dialog.setVisible(true);
                    }
                });
            }

        }, BorderLayout.EAST);
    }

    webPanel.add(operationPane, BorderLayout.NORTH);

    dataTable.setModel(getDataTableModel());
    WebScrollPane scrollPane = new WebScrollPane(dataTable);
    dataTable.setEditable(false);
    dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
    dataTable.setGridColor(Color.LIGHT_GRAY);
    dataTable.addMouseListener(new TableMouseAdapter(false));
    if (showPopmenu()) {
        final WebPopupMenu popupMenu = getTablePopupMenu(false);
        dataTable.setComponentPopupMenu(popupMenu);
        scrollPane.setComponentPopupMenu(popupMenu);
    }
    if (this instanceof PlayerPane) {
        dataTable.getSelectionModel().addListSelectionListener(e -> {
            if (e.getValueIsAdjusting() || dataTable.getRowCount() == 0 || dataTable.getSelectedRow() == -1) {
                return;
            }
            idTable.clearSelection();
            idTable.setModel(getIDTableModel());
        });
    }
    webPanel.add(scrollPane);
    webPanel.setMargin(5);
    return webPanel;
}



   protected WebPopupMenu getTablePopupMenu(boolean isIDTable) {
/* 345 */     WebPopupMenu popupMenu = new WebPopupMenu();
/* 346 */     for (Action action : getActions(isIDTable)) {
/* 347 */       if (isIDTable && action.getValue("Name").equals("编辑")) {
         continue;
       }
/* 350 */       popupMenu.add((JMenuItem)new WebMenuItem(action));
     }
/* 352 */     return popupMenu;
   }

   protected List<Action> getActions(boolean isIDTable) {
/* 356 */     List<Action> ret = new ArrayList<>();
/* 357 */     ret.add(getDefaultActionListener("新增", Start.loadIcon("add.png"), isIDTable));
/* 358 */     ret.add(getDefaultActionListener("删除", Start.loadIcon("off.png"), isIDTable));
/* 359 */     ret.add(getDefaultActionListener("编辑", Start.loadIcon("edit.png"), isIDTable));
/* 360 */     return ret;
   }

   private Action getDefaultActionListener(String name, ImageIcon icon, final boolean isIDTable) {
/* 364 */     return new AbstractAction(name, icon)
       {
         public void actionPerformed(ActionEvent e) {
/* 367 */           WebTable table = isIDTable ? TabbedPane.this.idTable : TabbedPane.this.dataTable;
/* 368 */           switch (e.getActionCommand()) {
             case "新增":
/* 370 */               TabbedPane.this.editAction(table, true, isIDTable);
               break;
             case "编辑":
/* 373 */               TabbedPane.this.editAction(table, false, isIDTable);
               break;
             case "删除":
/* 376 */               TabbedPane.this.removeAction(table, isIDTable);
               break;
           }
         }
       };
   }



   private void editAction(final WebTable table, final boolean add, final boolean isIDTable) {
/* 386 */     if (!isIDTable && this.idTable.getSelectedRow() == -1) {
/* 387 */       WebOptionPane.showMessageDialog((Component)this, "请先在左侧选择要添加分类名称", "警告", 0);
       return;
     }
/* 390 */     final String addtext = add ? "添加" : "修改";
/* 391 */     final WebDialog dialog = new WebDialog((Frame)this.owner, addtext + "数据", true);
/* 392 */     dialog.setResizable(false);
/* 393 */     GroupPanel mainPanel = new GroupPanel(false, new Component[0]);
/* 394 */     double[] doubles = new double[table.getColumnCount() + 1];
/* 395 */     Arrays.fill(doubles, 0, doubles.length, -2.0D);
/* 396 */     mainPanel.setLayout((LayoutManager)new TableLayout(new double[] { -2.0D, -1.0D }, doubles, 5, 5));
/* 397 */     final List<WebTextField> textFields = new ArrayList<>();
/* 398 */     for (int i = 0; i < table.getColumnCount(); i++) {
/* 399 */       final String columnName = table.getColumnName(i);
/* 400 */       if (!columnName.endsWith("名称")) {


/* 403 */         mainPanel.add((Component)new WebLabel(columnName, 11, new Object[0]), "0," + i);
/* 404 */         int finalI = i;
/* 405 */         textFields.add(new WebTextField(add ? (isIDTable ? "" : getDefaultDataVector().get(i)) : String.valueOf(table.getValueAt(table.getSelectedRow(), finalI)), 10)
             {

             });







/* 416 */         mainPanel.add((Component)textFields.get(textFields.size() - 1), "1," + i);
       }
/* 418 */     }  final DefaultTableModel tableModel = (DefaultTableModel)table.getModel();

/* 420 */     WebButton button_ok = new WebButton(addtext)
       {














































         private boolean hasName(int index)
         {
/* 470 */           return ((isIDTable && TabbedPane.this.hasNameIDTable(index)) || (!isIDTable && TabbedPane.this.hasNameDataTable(index)));
         }

         private String getNameByID(String name) {
/* 474 */           return isIDTable ? TabbedPane.this.getIDName(name) : TabbedPane.this.getDataName(name);
         }
       };
/* 477 */     WebButton button_cancel = new WebButton("取消")
       {

       };

/* 482 */     mainPanel.add((Component)new CenterPanel((Component)new GroupPanel(10, new Component[] { (Component)button_ok, (Component)button_cancel })), "0," + String.valueOf(doubles.length - 1) + ",1," + String.valueOf(doubles.length - 1));
/* 483 */     mainPanel.setMargin(10, 20, 10, 20);
/* 484 */     dialog.add((Component)mainPanel);
/* 485 */     HotkeyManager.registerHotkey((Component)dialog, (AbstractButton)button_ok, Hotkey.ENTER);
/* 486 */     HotkeyManager.registerHotkey((Component)dialog, (AbstractButton)button_cancel, Hotkey.ESCAPE);
/* 487 */     dialog.pack();
/* 488 */     dialog.setLocationRelativeTo((Component)this);
/* 489 */     dialog.setVisible(true);
   }



@SuppressWarnings("unchecked")
private void removeAction(WebTable table, boolean isIDTable) {
//        WebOptionPane.showMessageDialog(this, "该功能正在调整中,目前仅支持查询.", "警告", 0);
    int rowcount = table.getSelectedRowCount();
    if (WebOptionPane.showConfirmDialog(this, "确定要删除 " + rowcount + " 条记录吗？", "警告", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
        int[] rows = table.getSelectedRows();
        int i = 0;
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        for (int row : rows) {
            Vector<String> vector = (Vector<String>) model.getDataVector().get(row - i);
            addToChangeList(isIDTable ? DataMamageMode.ID_删除 : DataMamageMode.DATA_删除, getSelectedId(), vector);
//                if (mobidmodel.getRowCount() > 0) {
//                    addChangeValue(getSelectedId(), vector, new ChangeEntry(ChangeType.DELETE));
//                } else {
//                    addChangeValue("-1", vector, new ChangeEntry(ChangeType.DELETE));
//                }
            model.removeRow(row - i);
            i++;
        }
    }
}

   private String getSelectedId() {
/* 515 */     return String.valueOf(this.idTable.getValueAt(this.idTable.getSelectedRow(), 0));
   }


   protected void addToChangeList(DataMamageMode mode, String id, Vector<String> row) {}


   protected void applyChange(boolean change) {}

   protected boolean showOperation() {
/* 525 */     return true;
   }

   protected boolean showPopmenu() {
/* 529 */     return true;
   }

   protected boolean showEditColumn() {
/* 533 */     return false;
   }




   protected boolean isSelectedSearchResult() {
/* 540 */     return false;
   }




   protected boolean isSelectedSearchFuzzy() {
/* 547 */     return false;
   }

   protected boolean hasNameIDTable(int i) {
/* 551 */     return (i == 0);
   }

   protected boolean hasNameDataTable(int i) {
/* 555 */     return (i == 0);
   }

   private String getReplaceText(String text) {
/* 559 */     if (text.contains("百分比")) {
/* 560 */       return "%";
     }
/* 562 */     return "";
   }

   protected WebLabel createSwitchIcon(ImageIcon icon, int left, int right) {
/* 566 */     WebLabel rightComponent = new WebLabel(icon, 0);
/* 567 */     rightComponent.setMargin(2, left, 2, right);
/* 568 */     return rightComponent;
   }

   protected Vector<String> getDefaultDataVector() {
/* 572 */     return new Vector<>();
   }

   protected String getIDName(String id) {
/* 576 */     return null;
   }

   protected String getDataName(String id) {
/* 580 */     return null;
   }
   abstract void init();
   abstract String getTitle();

   private class TableMouseAdapter extends MouseAdapter { private final boolean isIDTable;

     public TableMouseAdapter(boolean isIDTable) {
/* 588 */       this.isIDTable = isIDTable;
     }



     public void mouseClicked(MouseEvent e) {
/* 594 */       if (!TabbedPane.this.showPopmenu()) {
         return;
       }

/* 598 */       if (!this.isIDTable && e.getClickCount() == 2) {
/* 599 */         TabbedPane.this.editAction((WebTable)e.getSource(), false, this.isIDTable);
       }
     }


     public void mousePressed(MouseEvent e) {
/* 605 */       if (SwingUtilities.isRightMouseButton(e)) {
/* 606 */         WebTable table = (WebTable)e.getComponent();
/* 607 */         int row = table.rowAtPoint(e.getPoint());
/* 608 */         if (!table.isRowSelected(row))
/* 609 */           table.setSelectedRow(row); 
       }
     } }

 }


/* Location:              C:\PGX\Server.jar!\server\console\groups\datamanage\TabbedPane.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */